import Vue from 'vue'
import App from './App.vue'
import store from './store'
import router from './router/router.js';
import Axios from 'axios'

import global from './pages/global'
import './assets/css/base.css'
import './assets/css/common.css'
import VueLazyLoad from 'vue-lazyload'
//懒加载的默认图片 
import def_lazy_img from './assets/images/lazy_load.png'
//使用懒加载组件
Vue.use(VueLazyLoad,{
	loading: def_lazy_img
})
if(global.IsPC()){
	require('./assets/layer/theme/default/layer.css')
	require('./assets/layer/layer')
}else{
	require('./assets/layer/mobile/need/layer.css')
	require('./assets/layer/mobile/layer')
}
var user_token = '';
if(global.is_weixin || global.IsPC()){
	if(global.getCookie('UNION_TOKEN') && global.getCookie('UNION_TOKEN')!=''){
		user_token = global.getCookie('UNION_TOKEN').split('#')[0];
	}else{
		if(global.is_weixin){
			if(top.location === self.location){
				location.href="http://login.1234tv.com/v1/users/wxLogin?service="+location.href	
			}
		}
	}
}else{
	if(global.getQueryString('deviceType')){
		if(global.getQueryString('utoken')){
			user_token = global.getQueryString('utoken')
		}
	}
}
if(top.location !== self.location){
	window.parent.postMessage({},'*');
}
Axios.defaults.baseURL = 'http://vend.1234tv.com/api';
Axios.defaults.headers.common['Content-Type'] = "application/x-www-form-urlencoded";
if(user_token){
	Axios.defaults.headers.common['Authorization'] = "Bearer "+user_token;
}

Vue.prototype.http = Axios;

/*视频组件*/
import VueVideoPlayer from 'vue-video-player'
import 'video.js/dist/video-js.css'
Vue.use(VueVideoPlayer)
router.beforeEach( ( to, from, next ) => {
   var _hmt = _hmt || [];
   (function() {
    //每次执行前，先移除上次插入的代码
    document.getElementById('baidu_tj') && document.getElementById('baidu_tj').remove();
    var hm = document.createElement("script");
    hm.src ="https://hm.baidu.com/hm.js?62e313227be5cc018ed96c8aca456d5a";
    hm.id ="baidu_tj"
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
   })();
   
    var _ybt = _ybt || [];
    (function() {
	    document.getElementById('yunbo_tj') && document.getElementById('yunbo_tj').remove();
	    var hm = document.createElement("script");
	    hm.src ="http://sta.1234tv.com/hm.js";
	    hm.id ="yunbo_tj"
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(hm, s);
    })();
	next();
 
} );
new Vue({
  el: '#app',
  router,
  render: h => h(App),
  store
})
